<template>
    <transition name="m-loading-fade">
        <div class="m-loading" v-if="visible">
            <div class="l-item l-item-1"></div>
            <div class="l-item l-item-2"></div>
            <div class="l-item l-item-3"></div>
            <div class="l-item l-item-4"></div>
            <div class="l-item l-item-5"></div>
        </div>
    </transition>
</template>

<script>
    export default {
        data() {
            return {
                visible: false
            }
        }
    }
</script>

<style lang="less" scoped>
    .m-loading {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        display: flex;
        align-items: center;
        width: 100px;
        height: 120px;
        z-index: 1001;

        .l-item {
            height: 100%;
            flex:1;
            -webkit-animation: stretch-delay 1.2s infinite ease-in-out;
            animation: stretch-delay 1.2s infinite ease-in-out;
            background: #007fff;

            &-2 {
                -webkit-animation-delay: -1.1s;
                animation-delay: -1.1s;
            }

            &-3 {
                -webkit-animation-delay: -1.0s;
                animation-delay: -1.0s;
            }

            &-4 {
                -webkit-animation-delay: -0.9s;
                animation-delay: -0.9s;
            }

            &-5 {
                -webkit-animation-delay: -0.8s;
                animation-delay: -0.8s;
            }
            &:not(:first-child){
                margin-left: 10px;
            }
        }
    }

    @-webkit-keyframes stretch-delay {
        0%, 40%, 100% {
            -webkit-transform: scaleY(0.4)
        }
        20% {
            -webkit-transform: scaleY(1.0)
        }
    }

    @keyframes stretch-delay {
        0%, 40%, 100% {
            transform: scaleY(0.4);
            -webkit-transform: scaleY(0.4);
        }
        20% {
            transform: scaleY(1.0);
            -webkit-transform: scaleY(1.0);
        }
    }

    .m-loading-fade-enter-active,
    .m-loading-fade-leave-active {
        transition: opacity 0.4s;
    }

    .m-loading-fade-enter,
    .m-loading-fade-leave-to {
        opacity: 0;
    }
</style>
